<?php

namespace App\Models;

use App\Models\Scope\OnSaleScope;
use Illuminate\Database\Eloquent\Model;

class Advertising extends Model
{
    protected $table = 'advertising';

    protected $hidden = [
        'created_at', 'updated_at', 'on_sale'
    ];

    protected static function boot()
    {
        parent::boot();

        //查询作用域
        static::addGlobalScope(new OnSaleScope());
    }

    public function getDataAttribute($value)
    {
        return json_decode($value, true);
    }

    public function getAdUrlAttribute($value)
    {
        if($value)
        {
            return $this->attributes['image'] = config('upload.ossUrl').$value;
        }else{
            return $this->attributes['image'] = '';
        }
    }
}
